<?php
date_default_timezone_set('Asia/Saigon');
?><?php
# MantisBT - a php based bugtracking system

# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT.  If not, see <http://www.gnu.org/licenses/>.

	/**
	 * @package MantisBT
	 * @copyright Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
	 * @copyright Copyright (C) 2002 - 2010  MantisBT Team - mantisbt-dev@lists.sourceforge.net
	 * @link http://www.mantisbt.org
	 */
	 /**
	  * MantisBT Core API's
	  */
	require_once( 'core.php' );
	require_once( 'current_user_api.php' );
	require_once( 'compress_api.php' );
	require_once( 'filter_api.php' );
	require_once( 'last_visited_api.php' );

	auth_ensure_user_authenticated();

	$t_current_user_name = current_user_get_field( 'username' );
	
	# Improve performance by caching category data in one pass
	category_get_all_rows( helper_get_current_project() );

	compress_enable();

	# don't index my view page
	html_robots_noindex();

	html_page_top1( lang_get( 'my_view_link' ) );

	if ( current_user_get_pref( 'refresh_delay' ) > 0 ) {
		html_meta_redirect( 'my_view_page.php', current_user_get_pref( 'refresh_delay' )*60 );
	}

	html_page_top2();

	print_recently_visited();

	$f_page_number		= gpc_get_int( 'page_number', 1 );

	$t_per_page = config_get( 'my_view_bug_count' );
	$t_bug_count = null;
	$t_page_count = null;

	$t_boxes = config_get( 'my_view_boxes' );
	asort ($t_boxes);
	reset ($t_boxes);
	#print_r ($t_boxes);

	$t_project_id = helper_get_current_project();
?>
<table border=0 cellspacing="3" cellpadding="0" width=100%>
			<tr>
				<td align="center">[<a href="?do=addcare">Add care</a>] | [<a href="?do=atme">Assign to me</a>] | [<a href="?do=viewall">View all</a>] | [<a href="?do=viewme">View me</a>] | [<a href="?do=monitor">View all monitor</a>] | [<a href="?do=recall">View all recall</a>] | <a href="?do=viewinc">[View Incomming]</a>
				| [<a href="?do=viewout">View Outgoing</a>] | [<a href="coogle.php">Search</a>] | [<a href="?do=download">Download</a>]
				</td>
			</tr>
</table>

<div align="center">
<table border=0 cellspacing="3" cellpadding="0" width=100%>
			<tr>
				<td>
				<?php 
					$do = $_GET['do'];
				
				//Add thông tin khách hàng
				if ($do == addcare)
				{			
							echo '
							 <html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Seller management Systems</title>
					<link rel="stylesheet" href="css/style.css" type="text/css">
					<title>Nhập contact khách hàng</title> 
					<style> 
					fieldset{display: none; padding: 10px;} 
					</style> 
					<script type="text/javascript"> 
					function toggleSet(rad) 
					{ 
					  var type = rad.value; 
					  for(var k=0,elm;elm=rad.form.elements[k];k++) 
						if(elm.className=="item") 
						  elm.style.display = elm.id==type? "inline":""; 
					} 
					</script> 
					</head>
					<body>		
						<form name="care" action="?do=pdata" method="post">
						<table border=1>
						<tr><td>
						<b>Nhập thông tin khách hàng</b>
						</td></tr>
						<tr><td>
						<table border=0>
							<tr><td>Name :</td><td><input name="name" type="name"></td><td>Phone :</td><td><input name="phone" type="phone"></td></tr>
							<tr>
							<td>Email :</td><td><input name="email" type="email"></td>
							<td> Sex : </td><td><Select name="sex">
								<option value =male>Male</option>
								<option value =female>Female</option>
								</select><br></td>
							</tr>
							<tr>
							<td>Address :</td><td><input name="address" type="address"><br></td>
							<td> Tỉnh/TP : </td><td><Select name="city">
								<option value =angiang>An Giang</option>
									<option value =brvt>bà rịa vũng tàu</option>
									<option value =bacgiang>bắc giang</option>
									<option value =baclieu>bạc liêu</option>
									<option value =baccan>bắc cạn</option>
									<option value =bacninh>bắc ninh</option>
									<option value =bentre>bến tre</option>
									<option value =binhdinh>bình định</option>
									<option value =binhduong>bình dương</option>
									<option value =binhphuoc>bình phước</option>
									<option value =binhthuan>bình thuận</option>
									<option value =camau>cà mau</option>
									<option value =caobang>cao bằng</option>
									<option value =cantho>cần thơ</option>
									<option value =danang>đà nẵng</option>
									<option value =dl>đắk lắk</option>
									<option value =dn>đắk nông</option>
									<option value =dienbien>điện biên</option>
									<option value =dongnai>đồng nai</option>
									<option value =dongthap>đồng tháp</option>
									<option value =gialai>gia lai</option>
									<option value =hagiang>hà giang</option>
									<option value =hanam>hà nam</option>
									<option value =hanoi>hà nội</option>
									<option value =hatinh>hà tĩnh</option>
									<option value =haiduong>hải dương</option>
									<option value =haiphong>hải phòng</option>
									<option value =haugiang>hậu giang</option>
									<option value =hoabinh>hòa bình</option>
									<option value =hcm>hcm</option>
									<option value =hungyen>hưng yên</option>
									<option value =khanhhoa>khánh hòa</option>
									<option value =kiengiang>kiên giang</option>
									<option value =kontum>kon tum</option>
									<option value =laichau>lai châu</option>
									<option value =lamdong>lam dong</option>
									<option value =langson>lạng sơn</option>
									<option value =laocai>lào cai</option>
									<option value =longan>long an</option>
									<option value =namdinh>nam định</option>
									<option value =nghean>nghệ an</option>
									<option value =ninhbinh>ninh bình</option>
									<option value =ninhthuan>ninh thuận</option>
									<option value =phutho>phú thọ</option>
									<option value =phuyen>phú yên</option>
									<option value =quangbinh>quảng bình</option>
									<option value =quangnam>quảng nam</option>
									<option value =quangngai>quảng ngãi</option>
									<option value =quangninh>quảng ninh</option>
									<option value =quangtri>quảng trị</option>
									<option value =soctrang>sóc trăng</option>
									<option value =sonla>sơn la</option>
									<option value =tayninh>tây ninh</option>
									<option value =thaibinh>thái bình</option>
									<option value =thainguyen>thái nguyên</option>
									<option value =thanhhoa>thanh hóa</option>
									<option value =thuathienhue>thừa thiên huế</option>
									<option value =tiengiang>tiền giang</option>
									<option value =travinh>trà vinh</option>
									<option value =tuyenquang>tuyên quang</option>
									<option value =vinhlong>vĩnh long</option>
									<option value =vinhphuc>vĩnh phúc</option>
									<option value =yenbai>yên bái</option>	
								</select><br></td></tr>
							<tr>
							<td>Serial :</td> <td> <input name="serial" type="serial"><br></td>
							<td>Lô :</td><td><input name="lo" type="lo"><br></td></tr>
							<tr>
							<td> Đối tượng: </td><td><Select name="dt">
								<option value =user>Khách hàng cá nhân</option>
								<option value =agent>Đại lí</option>
								</select><br></td></tr>
						</td></tr></table>
						</table>
						<br>
						<table border=1>
						<tr><td>
						<b>Nhập thông tin sự cố phản hồi</b>
						</td></tr>
						<tr><td>
						<table>
							<tr>
							<td> Object: </td><td><Select name="object">
								<option value =incomming>Gọi đến</option>
								<option value =outgoing>Gọi đi chăm sóc</option>
								<option value =1900>Dịch vụ 1900</option>
								</select><br></td></tr>
							<tr>
							<td> status: </td><td><Select name="status">
								<option value =virus>Dính virus</option>
								<option value =using>Cách sử dụng sản phẩm</option>
								<option value =License>Liên quan đến bản quyền</option>
								<option value =ProductError>Lỗi sản phẩm</option>
								<option value =ComputerError>Sự cố máy tính</option>
								<option value =other>Các vấn đề khác</option>
								</select><br></td></tr>
							<tr>
							<td> Complete  <input type="radio" name="itemtype" value="complete"  onclick="toggleSet(this)"></td>
							<td>  Move   <input type="radio" name="itemtype" value="move" onClick="toggleSet(this)"> </td> 
							</tr>
							<tr> <td></td>
								<td>
								  <fieldset id="complete" class="item"> 
									<legend>Complete</legend> 
									Đã xử lí xong
								  </fieldset>
								  <fieldset id="move" class="item"> 
									<legend>Move inforCare to other Supporter</legend> 
									 Supporter no.<Select name="receiver">';
									$req = mysql_query("select username from `mantis_user_table` where access_level='25'");
									while ($row = mysql_fetch_array($req)){
									if ($row['username'] != $seller)
									{
									 echo'
								<option value ='.$row['username'].'>'.$row['username'].'</option>';}}
								echo '
								</select><br> 
								  </fieldset> 
								  </td>
							 </tr>
							<tr>
							<td>| Confirm | :</td><td><textarea name="confirm" type="confirm" cols="44" rows="5"></textarea><br></td>
							</tr>
							<tr>
							<td>| Process | :</td><td><textarea name="process" type="process" cols="44" rows="5"></textarea></tr>
							<tr>
							<td><input name="submit" type="submit" value="submit"></td>
							</tr>
							</table>
							</td></tr></table>
							</form> 
							</body></html>
							';
						}
						
//Ghi dữ liệu khách hàng vào data
		if ($do == pdata)
		{
						echo '<html xmlns="http://www.w3.org/1999/xhtml">
						<head>
						<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
						<title>Seller management Systems</title>
						<link rel="stylesheet" href="css/style.css" type="text/css">
						</head>
						<body>
						';
						$seller = $t_current_user_name;
						//send information from form
						$name = $_POST['name'];
						$phone = $_POST['phone'];
						$email = $_POST['email'];
						$sex = $_POST['sex'];
						$address = $_POST['address'];
						$city = $_POST['city'];
						$serial = $_POST['serial'];
						$lo = $_POST['lo'];
						$dt = $_POST['dt'];
						$object = $_POST['object'];
						$status = $_POST['status'];
						$state = $_POST['itemtype'];
						$confirm = $_POST['confirm'];
						$process = $_POST['process'];
						$receiver = $_POST['receiver'];
						$time = date("H:i:s, d-m-Y");
						$start_time = time();
						
							//Them so vao Serial/Lo
							if(strlen($serial) == 4) {	$serial = '0'.$serial;}
							if(strlen($serial) == 3) {	$serial = '00'.$serial;}
							if(strlen($serial) == 2) {	$serial = '000'.$serial;}
							if(strlen($serial) == 1) {	$serial = '0000'.$serial;}
							//Insert contact khách hàng
								mysql_query("
								insert into `$db`.`contact` 
								(name, phone, email, address) 											
								values('$name','$phone','$email','$address')");
								echo '<div align=center><table border=1><tr><td align=center>';
							if ($state == complete){
							//Insert thong tin cham soc khach hang
								$mark = complete;
								mysql_query("
								insert into `mantis_care_report_table` 
								(name, phone, email, sex, address, city, serial , lo, dt, object, status, state, confirm, process, mark ,start_time, carer) 											
								values('$name','$phone','$email','$sex','$address','$city','$serial','$lo','$dt','$object','$status','$state','$confirm','$process', '$mark','$start_time','$seller')");
								echo "Bạn đã nhập dữ liệu khách hàng <b>".$name."</b> với số Serial/lo:[<b>".$serial."/".$lo."</b>] thành công<br>";
								echo "Check danh sách khách hàng chăm sóc trong ngày hôm nay";
								echo  "<div align=center><br><a href='?do=viewall'>[LIST]</a> | <a href='logout_page.php'>[Logout]</a></div>";
								}
							else 
							{							
							
							if ($state == move)
								{
								$mark = processing;
								
								mysql_query("
								insert into `mantis_care_report_table` 
								(name, phone, email, sex, address, city, serial , lo, dt, object, status, state, confirm, process, mark ,start_time, carer, receiver) 											
								values('$name','$phone','$email','$sex','$address','$city','$serial','$lo','$dt','$object','$status','$state','$confirm','$process', '$mark','$start_time','$seller','$receiver')");
								echo "Bạn đã nhập dữ liệu khách hàng <b>".$name."</b> với số Serial/lo:[<b>".$serial."/".$lo."</b>] thành công<br>";
								echo "Check danh sách khách hàng chăm sóc trong ngày hôm nay";
								echo  "<div align=center><br><a href='?do=viewall'>[LIST]</a> | <a href='logout_page.php'>[Logout]</a></div>";
								}
								else {echo 'chua chon trang thai kia ku';}
							}
							echo '</td></tr></table></div>';
		}
		
		//Hiển thị toàn bộ khách hàng được assign to me
		if ($do == atme)
		{
		
		echo ' <html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Seller management Systems</title>
					<link rel="stylesheet" href="css/default.css" type="text/css">
					<title></title> 
					</head>
					<body>	
					<table border=1 cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%> 
						<tr>
							<td>  <b>Viewing all report</b> [ Print Reports ]  [ CSV Export ]  [ Excel Export ]<br><br>    
								<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100% bgcolor=#CECEFF class=ttt>  
									<tr>
										<td width=4%>ID</td>
										<td width=4%>ED</td>
										<td width=10%>NAME</td>
										<td width=10%>CATEGORY</td>
										<td width=10%>STATUS</td>
										<td width=7%>Start time</td>
										<td width=7%>Last Update</td>
										<td width=7%>Start Supporter</td>
										<td width=7%>Last Supporter</td>
										<td width=22%>SUMMARY</td>
									</tr>
								</table><br>
								<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%>';
							$i = 0;
							$req = mysql_query("select * from `mantis_care_report_table` where `receiver`='$t_current_user_name' and `state`='move'");
							while ($row = mysql_fetch_array($req))
							{
									$i++;
									$id	= $row['id'];
									$name = $row['name'];
									$phone = $row['phone'];
									$email = $row['email'];
									$sex = $row['sex'];
									$address = $row['address'];
									$city = $row['city'];
									$serial = $row['serial'];
									$lo = $row['lo'];
									$object = $row['object'];
									$status = $row['status'];
									$state = $row['state'];
									$confirm = $row['confirm'];
									$process = $row['process'];
									$receiver = $row['receiver'];
									$carer = $row['carer'];
									
									// Max a last update

												$qr = "SELECT MAX(last_updated), cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by cid"; 
												$resultt = mysql_query($qr) or die(mysql_error());

												// Print out result
												while($row = mysql_fetch_array($resultt))
												{
													$cid = $row['cid'];
													$note = $row['note'];
													$resolver = $row['resolver'];
													$last_updated = (date("d-m-Y H:i",$row['MAX(last_updated)']));
												}	
									echo '<tr>
										<td width=4%   class='.$state.'>'.$i.'</td>
										<td width=4%   class='.$state.'><a href="view_care_report.php?do=view&id='.$id.'">'.$id.'</a></td>
										<td width=10%  class='.$state.'>'.$name.'</td>
										<td width=10%  class='.$state.'>'.$object.'</td>
										<td width=10%  class='.$state.'>'.$state.' (<a href="")>'.$receiver.'</a>)</td>
										<td width=7%   class='.$state.'>'.$start_time.'</td>
										<td width=7%   class='.$state.'>'.$last_updated.'</td>
										<td width=7%   class='.$state.'>'.$carer.'</td>
										<td width=7%   class='.$state.'>'.$resolver.'</td>
										<td width=22%  class='.$state.'>'.'</td>
										</tr>';					
							}
			echo '			</table><br>			
							+SEARCH	<form action="coogle.php?do=sc" method="POST" name="searching">
										<Select name="search">
										<option value=cname>Họ tên</option>
										<option value=cphone>Số điện thoại</option>
										<option value=cmail>Email</option>
										<option value=ccate>Category</option>
										<option value=cstatus>Status</option>
										<option value=cssupport>Start Support</option>
										</select>
										<input name="soption" type="soption">
										<input name="submit" type="submit" value="Find">
									</form>
							</td>
						</tr>
					</table>
					</body>
					</html>';
		}
		
		//Hiện thị toàn bộ danh khách hàng
		if ($do == viewall)
		{	
			$req = mysql_query("select * from `mantis_care_report_table` ORDER BY id DESC");
			echo ' <html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Seller management Systems</title>
					<link rel="stylesheet" href="css/default.css" type="text/css">
					<title></title> 
					</head>
					<body>	
					<table border=1 cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%> 
						<tr>
							<td>  <b>Viewing all report</b> [ Print Reports ]  [ CSV Export ]  [ Excel Export ]<br><br>    
								<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100% bgcolor=#CECEFF class=ttt>  
									<tr>
										<td width=4%>ID</td>
										<td width=4%>ED</td>
										<td width=10%>NAME</td>
										<td width=10%>CATEGORY</td>
										<td width=10%>STATUS</td>
										<td width=7%>Start time</td>
										<td width=7%>Last Update</td>
										<td width=7%>Start Supporter</td>
										<td width=7%>Last Supporter</td>
										<td width=22%>SUMMARY</td>
									</tr>
								</table><br>
								<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%>';
							$i = '0';
							
							
							while ($row = mysql_fetch_array($req))
							{	
									$i++;
									$id	= $row['id'];
									$name = $row['name'];
									$phone = $row['phone'];
									$email = $row['email'];
									$sex = $row['sex'];
									$address = $row['address'];
									$city = $row['city'];
									$serial = $row['serial'];
									$lo = $row['lo'];
									$object = $row['object'];
									$status = $row['status'];
									$state = $row['state'];
									$confirm = $row['confirm'];
									$process = $row['process'];
									$receiver = $row['receiver'];
									$carer = $row['carer'];
									$start_time = (date("d-m-Y H:i:s",$row['start_time']));
									$QueryDay = (date("d",$row['start_time']));
									$QueryCurrentDay = date("d");
									$QueryCurrentMonth = (date("m",$row['start_time']));
									$QueryMonth = date("m");
									
									if (($QueryDay == $QueryCurrentDay) and ($QueryCurrentMonth == $QueryMonth))
									{
									// Max a last update

												$qr = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by cid"; 
												$resultt = mysql_query($qr) or die(mysql_error());
												
												$qt = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by last_updated ORDER BY last_updated DESC LIMIT 0,1"; 
												$resultqt = mysql_query($qt) or die(mysql_error());
												// Print out result
													
									echo '<tr>
										<td width=4%   class='.$state.'>'.$i.'</td>
										<td width=4%   class='.$state.'><a href="view_care_report.php?do=view&id='.$id.'">'.$id.'</a></td>
										<td width=10%  class='.$state.'>'.$name.'</td>
										<td width=10%  class='.$state.'>'.$object.'</td>
										<td width=10%  class='.$state.'>'.$state.' (<a href="")>'.$receiver.'</a>)</td>
										<td width=7%   class='.$state.'>'.$start_time.'</td>
										<td width=7%   class='.$state.'>';
													while($row = mysql_fetch_array($resultt))
															{
																$cid = $row['cid'];
																$note = $row['note'];
																$resolver = $row['resolver'];
																$last_updated = (date("d-m-Y H:i:s",$row['MAX(last_updated)']));
																echo $last_updated;
															}	echo '</td>
										<td width=7%   class='.$state.'>'.$carer.'</td>
										<td width=7%   class='.$state.'>';
													while($row = mysql_fetch_array($resultqt))
															{
																$cid = $row['cid'];
																$note = $row['note'];
																$resolver = $row['resolver'];
																$last_updated = (date("d-m-Y H:i:s",$row['MAX(last_updated)']));
																echo $resolver;
															}	echo'</td>
									
										<td width=22% class='.$state.'>'.'</td>
										</tr>';					}
							}
			echo '			</table><br>			
							+SEARCH	<form action="coogle.php?do=sc" method="POST" name="searching">
										<Select name="search">
										<option value=cname>Họ tên</option>
										<option value=cphone>Số điện thoại</option>
										<option value=cmail>Email</option>
										<option value=ccate>Category</option>
										<option value=cstatus>Status</option>
										<option value=cssupport>Start Support</option>
										</select>
										<input name="soption" type="soption">
										<input name="submit" type="submit" value="Find">
									</form>
							</td>
						</tr>
					</table>
					</body>
					</html>';
		}
		
		//View cac khach hang cua Current user
		
			//Hiện thị toàn bộ danh khách hàng
		if ($do == viewme)
		{
			$t_current_user_name = current_user_get_field( 'username' );
			
			$req = mysql_query("select * from `mantis_care_report_table` where carer='$t_current_user_name' ORDER BY id DESC");
			echo ' <html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Seller management Systems</title>
					<link rel="stylesheet" href="css/default.css" type="text/css">
					<title></title> 
					</head>
					<body>	
					<table border=1 cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%> 
						<tr>
							<td>  <b>Viewing all report</b> [ Print Reports ]  [ CSV Export ]  [ Excel Export ]<br><br>    
								<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100% bgcolor=#CECEFF class=ttt>  
									<tr>
										<td width=4%>ID</td>
										<td width=4%>ED</td>
										<td width=10%>NAME</td>
										<td width=10%>CATEGORY</td>
										<td width=10%>STATUS</td>
										<td width=7%>Start time</td>
										<td width=7%>Last Update</td>
										<td width=7%>Start Supporter</td>
										<td width=7%>Last Supporter</td>
										<td width=22%>SUMMARY</td>
									</tr>
								</table><br>
								<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%>';
							$i = '0';
							while ($row = mysql_fetch_array($req))
							{	
									$i++;
									$id	= $row['id'];
									$name = $row['name'];
									$phone = $row['phone'];
									$email = $row['email'];
									$sex = $row['sex'];
									$address = $row['address'];
									$city = $row['city'];
									$serial = $row['serial'];
									$lo = $row['lo'];
									$object = $row['object'];
									$status = $row['status'];
									$state = $row['state'];
									$confirm = $row['confirm'];
									$process = $row['process'];
									$receiver = $row['receiver'];
									$carer = $row['carer'];
									$start_time = (date("d-m-Y H:i:s",$row['start_time']));
									// Max a last update

												$qr = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by cid"; 
												$resultt = mysql_query($qr) or die(mysql_error());
												
												$qt = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by last_updated ORDER BY last_updated DESC LIMIT 0,1"; 
												$resultqt = mysql_query($qt) or die(mysql_error());
												// Print out result
													
									echo '<tr>
										<td width=4%   class='.$state.'>'.$i.'</td>
										<td width=4%   class='.$state.'><a href="view_care_report.php?do=view&id='.$id.'">'.$id.'</a></td>
										<td width=10%  class='.$state.'>'.$name.'</td>
										<td width=10%  class='.$state.'>'.$object.'</td>
										<td width=10%  class='.$state.'>'.$state.' (<a href="")>'.$receiver.'</a>)</td>
										<td width=7%   class='.$state.'>'.$start_time.'</td>
										<td width=7%   class='.$state.'>';
													while($row = mysql_fetch_array($resultt))
															{
																$cid = $row['cid'];
																$note = $row['note'];
																$resolver = $row['resolver'];
																$last_updated = (date("d-m-Y H:i:s",$row['MAX(last_updated)']));
																echo $last_updated;
															}	echo '</td>
										<td width=7%   class='.$state.'>'.$carer.'</td>
										<td width=7%   class='.$state.'>';
													while($row = mysql_fetch_array($resultqt))
															{
																$cid = $row['cid'];
																$note = $row['note'];
																$resolver = $row['resolver'];
																$last_updated = (date("d-m-Y H:i:s",$row['MAX(last_updated)']));
																echo $resolver;
															}	echo'</td>
									
										<td width=22% class='.$state.'>'.'</td>
										</tr>';					
							}
			echo '			</table><br>			
							+SEARCH	<form action="coogle.php?do=sc" method="POST" name="searching">
										<Select name="search">
										<option value=cname>Họ tên</option>
										<option value=cphone>Số điện thoại</option>
										<option value=cmail>Email</option>
										<option value=ccate>Category</option>
										<option value=cstatus>Status</option>
										<option value=cssupport>Start Support</option>
										</select>
										<input name="soption" type="soption">
										<input name="submit" type="submit" value="Find">
									</form>
							</td>
						</tr>
					</table>
					</body>
					</html>';
		}
		//View các khách hàng gọi đến
		if ($do == viewinc)
		{
			$req = mysql_query("select * from `mantis_care_report_table` where object='incomming' ORDER BY id DESC");
			echo ' <html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Seller management Systems</title>
					<link rel="stylesheet" href="css/default.css" type="text/css">
					<title></title> 
					</head>
					<body>	
					<table border=1 cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%> 
						<tr>
							<td>  <b>Viewing all report</b> [ Print Reports ]  [ CSV Export ]  [ Excel Export ]<br><br>    
								<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100% bgcolor=#CECEFF class=ttt>  
									<tr>
										<td width=4%>ID</td>
										<td width=4%>ED</td>
										<td width=10%>NAME</td>
										<td width=10%>CATEGORY</td>
										<td width=10%>STATUS</td>
										<td width=7%>Start time</td>
										<td width=7%>Last Update</td>
										<td width=7%>Start Supporter</td>
										<td width=7%>Last Supporter</td>
										<td width=22%>SUMMARY</td>
									</tr>
								</table><br>
								<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%>';
							$i = 0;
							while ($row = mysql_fetch_array($req))
							{
									$i++;
									$id	= $row['id'];
									$name = $row['name'];
									$phone = $row['phone'];
									$email = $row['email'];
									$sex = $row['sex'];
									$address = $row['address'];
									$city = $row['city'];
									$serial = $row['serial'];
									$lo = $row['lo'];
									$object = $row['object'];
									$status = $row['status'];
									$state = $row['state'];
									$confirm = $row['confirm'];
									$process = $row['process'];
									$receiver = $row['receiver'];
									$carer = $row['carer'];
									$start_time = (date("d-m-Y H:i:s",$row['start_time']));
									$QueryDay = (date("d",$row['start_time']));
									$QueryCurrentDay = date("d");
									$QueryCurrentMonth = (date("m",$row['start_time']));
									$QueryMonth = date("m");
									
									if (($QueryDay == $QueryCurrentDay) and ($QueryCurrentMonth == $QueryMonth))
									{
									// Max a last update

												$qr = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by cid"; 
												$resultt = mysql_query($qr) or die(mysql_error());
												
												$qt = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by last_updated ORDER BY last_updated DESC LIMIT 0,1"; 
												$resultqt = mysql_query($qt) or die(mysql_error());
												// Print out result
													
									echo '<tr>
										<td width=4% class='.$state.'>'.$i.'</td>
										<td width=4% class='.$state.'><a href="view_care_report.php?do=view&id='.$id.'">'.$id.'</td>
										<td width=10% class='.$state.'>'.$name.'</td>
										<td width=10% class='.$state.'>'.$object.'</td>
										<td width=10% class='.$state.'>'.$state.' (<a href="")>'.$receiver.'</a>)</td>
										<td width=7%  class='.$state.'>'.$start_time.'</td>
										<td width=7%  class='.$state.'>';
													while($row = mysql_fetch_array($resultt))
															{
																$cid = $row['cid'];
																$note = $row['note'];
																$resolver = $row['resolver'];
																$last_updated = (date("d-m-Y H:i:s",$row['MAX(last_updated)']));
																echo $last_updated;
															}	echo '</td>
										<td width=7%  class='.$state.'>'.$carer.'</td>
										<td width=7%  class='.$state.'>';
													while($row = mysql_fetch_array($resultqt))
															{
																$cid = $row['cid'];
																$note = $row['note'];
																$resolver = $row['resolver'];
																$last_updated = (date("d-m-Y H:i:s",$row['MAX(last_updated)']));
																echo $resolver;
															}	echo'</td>
									
										<td width=22%  class='.$state.'>'.'</td>
										</tr>';	
									}										
							}
			echo '			</table><br>			
							+SEARCH	<form action="coogle.php?do=sc" method="POST" name="searching">
										<Select name="search">
										<option value=cname>Họ tên</option>
										<option value=cphone>Số điện thoại</option>
										<option value=cmail>Email</option>
										<option value=ccate>Category</option>
										<option value=cstatus>Status</option>
										<option value=cssupport>Start Support</option>
										</select>
										<input name="soption" type="soption">
										<input name="submit" type="submit" value="Find">
									</form>
							</td>
						</tr>
					</table>
					</body>
					</html>';
		}
		
		if ($do == viewout)
		{
			$req = mysql_query("select * from `mantis_care_report_table` where object='outgoing' ORDER BY id DESC");
			echo ' <html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Seller management Systems</title>
					<link rel="stylesheet" href="css/default.css" type="text/css">
					<title></title> 
					</head>
					<body>	
					<table border=1 cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%> 
						<tr>
							<td>  <b>Viewing all report</b> [ Print Reports ]  [ CSV Export ]  [ Excel Export ]<br><br>    
								<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100% bgcolor=#CECEFF class=ttt>  
									<tr>
										<td width=4%>ID</td>
										<td width=4%>ED</td>
										<td width=10%>NAME</td>
										<td width=10%>CATEGORY</td>
										<td width=10%>STATUS</td>
										<td width=7%>Start time</td>
										<td width=7%>Last Update</td>
										<td width=7%>Start Supporter</td>
										<td width=7%>Last Supporter</td>
										<td width=22%>SUMMARY</td>
									</tr>
								</table><br>
								<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%>';
							$i = 0;
							while ($row = mysql_fetch_array($req))
							{
									$i++;
									$id	= $row['id'];
									$name = $row['name'];
									$phone = $row['phone'];
									$email = $row['email'];
									$sex = $row['sex'];
									$address = $row['address'];
									$city = $row['city'];
									$serial = $row['serial'];
									$lo = $row['lo'];
									$object = $row['object'];
									$status = $row['status'];
									$state = $row['state'];
									$confirm = $row['confirm'];
									$process = $row['process'];
									$receiver = $row['receiver'];
									$carer = $row['carer'];
									$start_time = (date("d-m-Y H:i:s",$row['start_time']));
									$QueryDay = (date("d",$row['start_time']));
									$QueryCurrentDay = date("d");
									$QueryCurrentMonth = (date("m",$row['start_time']));
									$QueryMonth = date("m");
									
									if (($QueryDay == $QueryCurrentDay) and ($QueryCurrentMonth == $QueryMonth))
									{
									// Max a last update

												$qr = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by cid"; 
												$resultt = mysql_query($qr) or die(mysql_error());
												
												$qt = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by last_updated ORDER BY last_updated DESC LIMIT 0,1"; 
												$resultqt = mysql_query($qt) or die(mysql_error());
												// Print out result
													
									echo '<tr>
										<td width=4%   class='.$state.'>'.$i.'</td>
										<td width=4%   class='.$state.'><a href="view_care_report.php?do=view&id='.$id.'">'.$id.'</a></td>
										<td width=10%  class='.$state.'>'.$name.'</td>
										<td width=10%  class='.$state.'>'.$object.'</td>
										<td width=10%  class='.$state.'>'.$state.' (<a href="")>'.$receiver.'</a>)</td>
										<td width=7%   class='.$state.'>'.$start_time.'</td>
										<td width=7%   class='.$state.'>';
													while($row = mysql_fetch_array($resultt))
															{
																$cid = $row['cid'];
																$note = $row['note'];
																$resolver = $row['resolver'];
																$last_updated = (date("d-m-Y H:i:s",$row['MAX(last_updated)']));
																echo $last_updated;
															}	echo '</td>
										<td width=7%  class='.$state.'>'.$carer.'</td>
										<td width=7%  class='.$state.'>';
													while($row = mysql_fetch_array($resultqt))
															{
																$cid = $row['cid'];
																$note = $row['note'];
																$resolver = $row['resolver'];
																$last_updated = (date("d-m-Y H:i:s",$row['MAX(last_updated)']));
																echo $resolver;
															}	echo'</td>
									
										<td width=22%  class='.$state.'>'.'</td>
										</tr>';	
									}
							}
			echo '			</table><br>			
							+SEARCH	<form action="coogle.php?do=sc" method="POST" name="searching">
										<Select name="search">
										<option value=cname>Họ tên</option>
										<option value=cphone>Số điện thoại</option>
										<option value=cmail>Email</option>
										<option value=ccate>Category</option>
										<option value=cstatus>Status</option>
										<option value=cssupport>Start Support</option>
										</select>
										<input name="soption" type="soption">
										<input name="submit" type="submit" value="Find">
									</form>
							</td>
						</tr>
					</table>
					</body>
					</html>';
		}
		
		
		if ($do == monitor)
		{
			$req = mysql_query("select * from `mantis_care_report_table` where state='monitor' ORDER BY id DESC");
			echo ' <html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Seller management Systems</title>
					<link rel="stylesheet" href="css/default.css" type="text/css">
					<title></title> 
					</head>
					<body>	
					<table border=1 cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%> 
						<tr>
							<td>  <b>Viewing all report</b> [ Print Reports ]  [ CSV Export ]  [ Excel Export ]<br><br>    
								<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100% bgcolor=#CECEFF class=ttt>  
									<tr>
										<td width=4%>ID</td>
										<td width=4%>ED</td>
										<td width=10%>NAME</td>
										<td width=10%>CATEGORY</td>
										<td width=10%>STATUS</td>
										<td width=7%>Start time</td>
										<td width=7%>Last Update</td>
										<td width=7%>Start Supporter</td>
										<td width=7%>Last Supporter</td>
										<td width=22%>SUMMARY</td>
									</tr>
								</table><br>
								<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%>';
							$i = 0;
							while ($row = mysql_fetch_array($req))
							{
									$i++;
									$id	= $row['id'];
									$name = $row['name'];
									$phone = $row['phone'];
									$email = $row['email'];
									$sex = $row['sex'];
									$address = $row['address'];
									$city = $row['city'];
									$serial = $row['serial'];
									$lo = $row['lo'];
									$object = $row['object'];
									$status = $row['status'];
									$state = $row['state'];
									$confirm = $row['confirm'];
									$process = $row['process'];
									$receiver = $row['receiver'];
									$carer = $row['carer'];
									$start_time = (date("d-m-Y H:i:s",$row['start_time']));
									$QueryDay = (date("d",$row['start_time']));
									$QueryCurrentDay = date("d");
									$QueryCurrentMonth = (date("m",$row['start_time']));
									$QueryMonth = date("m");
									
									
									// Max a last update

												$qr = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by cid"; 
												$resultt = mysql_query($qr) or die(mysql_error());
												
												$qt = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by last_updated ORDER BY last_updated DESC LIMIT 0,1"; 
												$resultqt = mysql_query($qt) or die(mysql_error());
												// Print out result
													
									echo '<tr>
										<td width=4%   class='.$state.'>'.$i.'</td>
										<td width=4%   class='.$state.'><a href="view_care_report.php?do=view&id='.$id.'">'.$id.'</a></td>
										<td width=10%  class='.$state.'>'.$name.'</td>
										<td width=10%  class='.$state.'>'.$object.'</td>
										<td width=10%  class='.$state.'>'.$state.' (<a href="")>'.$receiver.'</a>)</td>
										<td width=7%   class='.$state.'>'.$start_time.'</td>
										<td width=7%   class='.$state.'>';
													while($row = mysql_fetch_array($resultt))
															{
																$cid = $row['cid'];
																$note = $row['note'];
																$resolver = $row['resolver'];
																$last_updated = (date("d-m-Y H:i:s",$row['MAX(last_updated)']));
																echo $last_updated;
															}	echo '</td>
										<td width=7%  class='.$state.'>'.$carer.'</td>
										<td width=7%  class='.$state.'>';
													while($row = mysql_fetch_array($resultqt))
															{
																$cid = $row['cid'];
																$note = $row['note'];
																$resolver = $row['resolver'];
																$last_updated = (date("d-m-Y H:i:s",$row['MAX(last_updated)']));
																echo $resolver;
															}	echo'</td>
									
										<td width=22%  class='.$state.'>'.'</td>
										</tr>';	
									
							}
			echo '			</table><br>			
							+SEARCH	<form action="coogle.php?do=sc" method="POST" name="searching">
										<Select name="search">
										<option value=cname>Họ tên</option>
										<option value=cphone>Số điện thoại</option>
										<option value=cmail>Email</option>
										<option value=ccate>Category</option>
										<option value=cstatus>Status</option>
										<option value=cssupport>Start Support</option>
										</select>
										<input name="soption" type="soption">
										<input name="submit" type="submit" value="Find">
									</form>
							</td>
						</tr>
					</table>
					</body>
					</html>';
		}
		
		if ($do == recall)
		{
			$req = mysql_query("select * from `mantis_care_report_table` where state='recall' ORDER BY id DESC");
			echo ' <html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Seller management Systems</title>
					<link rel="stylesheet" href="css/default.css" type="text/css">
					<title></title> 
					</head>
					<body>	
					<table border=1 cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%> 
						<tr>
							<td>  <b>Viewing all report</b> [ Print Reports ]  [ CSV Export ]  [ Excel Export ]<br><br>    
								<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100% bgcolor=#CECEFF class=ttt>  
									<tr>
										<td width=4%>ID</td>
										<td width=4%>ED</td>
										<td width=10%>NAME</td>
										<td width=10%>CATEGORY</td>
										<td width=10%>STATUS</td>
										<td width=7%>Start time</td>
										<td width=7%>Last Update</td>
										<td width=7%>Start Supporter</td>
										<td width=7%>Last Supporter</td>
										<td width=22%>SUMMARY</td>
									</tr>
								</table><br>
								<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%>';
							$i = 0;
							while ($row = mysql_fetch_array($req))
							{
									$i++;
									$id	= $row['id'];
									$name = $row['name'];
									$phone = $row['phone'];
									$email = $row['email'];
									$sex = $row['sex'];
									$address = $row['address'];
									$city = $row['city'];
									$serial = $row['serial'];
									$lo = $row['lo'];
									$object = $row['object'];
									$status = $row['status'];
									$state = $row['state'];
									$confirm = $row['confirm'];
									$process = $row['process'];
									$receiver = $row['receiver'];
									$carer = $row['carer'];
									$start_time = (date("d-m-Y H:i:s",$row['start_time']));
									$QueryDay = (date("d",$row['start_time']));
									$QueryCurrentDay = date("d");
									$QueryCurrentMonth = (date("m",$row['start_time']));
									$QueryMonth = date("m");
									
									// Max a last update

												$qr = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by cid"; 
												$resultt = mysql_query($qr) or die(mysql_error());
												
												$qt = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by last_updated ORDER BY last_updated DESC LIMIT 0,1"; 
												$resultqt = mysql_query($qt) or die(mysql_error());
												// Print out result
													
									echo '<tr>
										<td width=4%   class='.$state.'>'.$i.'</td>
										<td width=4%   class='.$state.'><a href="view_care_report.php?do=view&id='.$id.'">'.$id.'</a></td>
										<td width=10%  class='.$state.'>'.$name.'</td>
										<td width=10%  class='.$state.'>'.$object.'</td>
										<td width=10%  class='.$state.'>'.$state.' (<a href="")>'.$receiver.'</a>)</td>
										<td width=7%   class='.$state.'>'.$start_time.'</td>
										<td width=7%   class='.$state.'>';
													while($row = mysql_fetch_array($resultt))
															{
																$cid = $row['cid'];
																$note = $row['note'];
																$resolver = $row['resolver'];
																$last_updated = (date("d-m-Y H:i:s",$row['MAX(last_updated)']));
																echo $last_updated;
															}	echo '</td>
										<td width=7%  class='.$state.'>'.$carer.'</td>
										<td width=7%  class='.$state.'>';
													while($row = mysql_fetch_array($resultqt))
															{
																$cid = $row['cid'];
																$note = $row['note'];
																$resolver = $row['resolver'];
																$last_updated = (date("d-m-Y H:i:s",$row['MAX(last_updated)']));
																echo $resolver;
															}	echo'</td>
									
										<td width=22%  class='.$state.'>'.'</td>
										</tr>';	
									
							}
			echo '			</table><br>			
							+SEARCH	<form action="coogle.php?do=sc" method="POST" name="searching">
										<Select name="search">
										<option value=cname>Họ tên</option>
										<option value=cphone>Số điện thoại</option>
										<option value=cmail>Email</option>
										<option value=ccate>Category</option>
										<option value=cstatus>Status</option>
										<option value=cssupport>Start Support</option>
										</select>
										<input name="soption" type="soption">
										<input name="submit" type="submit" value="">
									</form>
							</td>
						</tr>
					</table>
					</body>
					</html>';
		}
		
		if ($do == manage)
		{
			echo 'Manage';
		}
		
		if ($do == download)
		{
			echo 'download';
		}
		?>
					</td>
				</tr>
			</table>
</div>

<?php
	html_page_bottom();
